package april.fastjson.valuefilter;

import java.util.HashMap;
import java.util.Map;

import com.alibaba.fastjson.serializer.JSONSerializer;
import com.alibaba.fastjson.serializer.SerializeWriter;
import com.alibaba.fastjson.serializer.ValueFilter;

public class ValueFilterDemo {

	public static void main(String[] args) {

		ValueFilter filter = new ValueFilter() {

			@Override
			public Object process(Object source, String name, Object value) {
				if ("name".equals(name)) {
					return null;
				}

				return value;
			}
		};

		SerializeWriter out = new SerializeWriter();

		JSONSerializer serializer = new JSONSerializer(out);

		serializer.getValueFilters().add(filter);

		Map<String, String> map = new HashMap<String, String>();
		map.put("name", "andy");
		map.put("sex", "male");

		serializer.write(map);
		String text = out.toString();

		System.out.println(text);

	}

}
